package com.wujiale.javacore.stream;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;

public class CountLongWords {
    public static void main(String[] args) throws IOException {
        File file = new File("");
        String canonicalPath = file.getCanonicalPath();
        var contents = new String(Files.readAllBytes(
                Paths.get(canonicalPath + "/src/main/resources/stream/alice30.txt")
        ), StandardCharsets.UTF_8);
        List<String> words = List.of(contents.split(","));
        System.out.println(words);

        long count = 0;

        for (String s : words){
            if (s.length() > 12){
                count ++;
            }
        }
        System.out.println(count);

        count = words.stream().filter(w -> w.length() > 12).count();
        System.out.println(count);

        words.parallelStream().filter(w -> w.length() > 12).count();
        System.out.println(count);
    }
}
